﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using hcom;
using System.Data;

namespace hcms.Admin
{
	public partial class UserList : System.Web.UI.Page
	{
		public Model model = Global.model;
		public DataRowCollection rows;
		public int page;					// 页号，从1开始
		public int pages;					// 页数
		protected void Page_Load(object sender, EventArgs e)
		{
			page = Request["page"] == null ? 1 : int.Parse(Request["page"]);
			if (Page.IsPostBack)	// 页面提交
			{
				switch (cmd.Value)
				{
					case "delete":
						delete();
						break;

					case "search":
						break;

					default:
						throw (new Exception("不可识别的提交命令: " + cmd.Value));
				}
			}
			else
				idsearch.Value = Request["search"];	// 换页后传进搜索词

			int pagerows = 25;		// 每页行数
			rows = model.getUserRows(ref page, pagerows, ref pages, idsearch.Value);
		}

		private void delete()
		{
			// 删除选择的用户，sel.Value格式“uid1, uid2, uid3,”， 不删除该用户文章和评论。
			string strsql = string.Format("UPDATE hcms_Users SET userDeleted = 1 WHERE (userID IN ('{0}'))",
				sel.Value.Replace(",", "','"));	// 把id加上引号变成字符串形式
			model.da.Execute(strsql);
			//Response.Write("<script>alert('删除完毕。');</script>"); 用这个样式就没装进来。
			ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "alert('删除完毕。')", true);
		}


	}
}